<?php

//定义常量TOKEN


define("TOKEN", "98ab085513424d0cb7762b0b93727d7d");  //lgl


//微信服务器验证类
class verify{
    //微信服务器验证函数
    public function valid(){
        $echoStr = $_GET["echostr"];
        if($this->checkSignature()){
            echo $echoStr;
            exit;
        }
    }

    //签名检查函数
    private function checkSignature(){
        $signature = $_GET["signature"];
        $timestamp = $_GET["timestamp"];
        $nonce = $_GET["nonce"];

        $token = TOKEN;
        $tmpArr = array($token, $timestamp, $nonce);
        sort($tmpArr);
        $tmpStr = implode( $tmpArr );
        $tmpStr = sha1( $tmpStr );

        if( $tmpStr == $signature ){
            return true;
        }
        else{
            return false;
        }
    }    
} 
?>